package com.mall.order.utils;

import org.apache.commons.lang3.RandomStringUtils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class OrderUtils {

	// 生成订单号
    public static String generateOrderSn() {
        final Date now = Calendar.getInstance().getTime();
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        StringBuffer businessKey = new StringBuffer(format.format(now));
        String numeric = RandomStringUtils.randomNumeric(6);
        businessKey.append(numeric);
        return businessKey.toString();
    }
    
    // 生成交易流水号：订单号后6位 + 时间戳
    public static String generateTranNo(String orderSn) {
    	final Date now = Calendar.getInstance().getTime();
    	SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
    	StringBuffer businessKey = new StringBuffer(orderSn.substring(orderSn.length() - 6));
    	businessKey.append(format.format(now));
    	return businessKey.toString();
    }
    
}
